import {MessageSent} from "../generated/circle/cctp/v1/events";


const config = require('../config');
const attestationApi = config.attestationApi.url;
const axios = require('axios');
const { IndexedTx,SigningStargateClient, StargateClient } = require("@cosmjs/stargate")
const { MsgDepositForBurn, MsgSendMessage } = require("../generated/circle/cctp/v1/tx")
const Web3 = require('web3');
const web3 = new Web3();

const run = async ()=>{

    const rpc = config.noble.url;

    const client = await StargateClient.connect(rpc)
    let tx = await client.getTx("57D3A0C04C2CFAC21A75D25CC682BCEDDE575256DC067691600004CFF35416BB")
    //console.log('tx: ',tx);
    let events = tx.events;
    let message;
    for(let event of events) {
        if(event.type === "circle.cctp.v1.MessageSent"){
            message = event.attributes;
            break;
        }
    }
    let m1 = message[0].value;
    console.log('m1: ',m1);

    let tempMessage = m1.substr(1,m1.length-2);
    console.log("tempMessage: ", tempMessage)
    var b = Buffer.from(tempMessage, 'base64')
    console.log('b: ', b.toString('hex'));
    const messageHash = web3.utils.keccak256(b);
    console.log('messageHash: ', messageHash);
    const circleUrl = attestationApi + messageHash;
    console.log('circleUrl:', circleUrl)
    //const res = await axios.get(circleUrl);
    //console.log('res.data', res.data);
}

run();